<?php

namespace App\Http\Controllers;

use App\Http\Resources\MenuResource;
use App\Http\Services\MenuService;
use App\Http\Traits\ApiReturn;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\Hash;

class MenuController extends BaseController
{
    use ApiReturn;
    protected $service;
    public function __construct(Request $request,MenuService $menuService)
    {
        $this->service = $menuService;
        $this->request = $request;
        parent::__construct($request);
    }
    public function routes(){
        $data = [
            [
                'path' => '/system',
                'component' => 'Layout',
                'redirect' => '/system/user',
                'name' => '/system',
                'meta' => [
                    'title' => '系统管理',
                    'icon' => 'system',
                    'hidden' => false,
                    'roles' => ['ADMIN'],
                    'alwaysShow' => false,
                    'params' => null,
                ],
                'children' => [
                    [
                        'path' => 'user',
                        'component' => 'system/user/index',
                        'name' => 'User',
                        'meta' => [
                            'title' => '用户管理',
                            'icon' => 'user',
                            'hidden' => false,
                            'roles' => ['ADMIN'],
                            'keepAlive' => true,
                            'alwaysShow' => false,
                            'params' => null,
                        ],
                    ],
                    [
                        'path' => 'role',
                        'component' => 'system/role/index',
                        'name' => 'Role',
                        'meta' => [
                            'title' => '角色管理',
                            'icon' => 'role',
                            'hidden' => false,
                            'roles' => ['ADMIN'],
                            'keepAlive' => true,
                            'alwaysShow' => false,
                            'params' => null,
                        ],
                    ],
                    [
                        'path' => 'menu',
                        'component' => 'system/menu/index',
                        'name' => 'Menu',
                        'meta' => [
                            'title' => '菜单管理',
                            'icon' => 'menu',
                            'hidden' => false,
                            'roles' => ['ADMIN'],
                            'keepAlive' => true,
                            'alwaysShow' => false,
                            'params' => null,
                        ],
                    ],
                    [
                        'path' => 'dept',
                        'component' => 'system/dept/index',
                        'name' => 'Dept',
                        'meta' => [
                            'title' => '部门管理',
                            'icon' => 'tree',
                            'hidden' => false,
                            'roles' => ['ADMIN'],
                            'keepAlive' => true,
                            'alwaysShow' => false,
                            'params' => null,
                        ],
                    ],
                    [
                        'path' => 'dict',
                        'component' => 'system/dict/index',
                        'name' => 'Dict',
                        'meta' => [
                            'title' => '字典管理',
                            'icon' => 'dict',
                            'hidden' => false,
                            'roles' => ['ADMIN'],
                            'keepAlive' => true,
                            'alwaysShow' => false,
                            'params' => null,
                        ],
                    ],
                ],
            ],
            [
                'path' => '/api',
                'component' => 'Layout',
                'name' => '/api',
                'meta' => [
                    'title' => '接口文档',
                    'icon' => 'api',
                    'hidden' => false,
                    'roles' => ['ADMIN'],
                    'alwaysShow' => true,
                    'params' => null,
                ],
                'children' => [
                    [
                        'path' => 'apifox',
                        'component' => 'demo/api/apifox',
                        'name' => 'Apifox',
                        'meta' => [
                            'title' => 'Apifox',
                            'icon' => 'api',
                            'hidden' => false,
                            'roles' => ['ADMIN'],
                            'keepAlive' => true,
                            'alwaysShow' => false,
                            'params' => null,
                        ],
                    ],
                ],
            ],
            [
                'path' => '/doc',
                'component' => 'Layout',
                'redirect' => 'https://juejin.cn/post/7228990409909108793',
                'name' => '/doc',
                'meta' => [
                    'title' => '平台文档',
                    'icon' => 'document',
                    'hidden' => false,
                    'roles' => ['ADMIN'],
                    'alwaysShow' => false,
                    'params' => null,
                ],
                'children' => [
                    [
                        'path' => 'internal-doc',
                        'component' => 'demo/internal-doc',
                        'name' => 'InternalDoc',
                        'meta' => [
                            'title' => '平台文档(内嵌)',
                            'icon' => 'document',
                            'hidden' => false,
                            'roles' => ['ADMIN'],
                            'alwaysShow' => false,
                            'params' => null,
                        ],
                    ],
                    [
                        'path' => 'https://juejin.cn/post/7228990409909108793',
                        'name' => 'Https://juejin.cn/post/7228990409909108793',
                        'meta' => [
                            'title' => '平台文档(外链)',
                            'icon' => 'link',
                            'hidden' => false,
                            'roles' => ['ADMIN'],
                            'alwaysShow' => false,
                            'params' => null,
                        ],
                    ],
                ],
            ],
            [
                'path' => '/multi-level',
                'component' => 'Layout',
                'name' => '/multiLevel',
                'meta' => [
                    'title' => '多级菜单',
                    'icon' => 'cascader',
                    'hidden' => false,
                    'roles' => ['ADMIN'],
                    'alwaysShow' => true,
                    'params' => null,
                ],
                'children' => [
                    [
                        'path' => 'multi-level1',
                        'component' => 'demo/multi-level/level1',
                        'name' => 'MultiLevel1',
                        'meta' => [
                            'title' => '菜单一级',
                            'icon' => '',
                            'hidden' => false,
                            'roles' => ['ADMIN'],
                            'alwaysShow' => true,
                            'params' => null,
                        ],
                        'children' => [
                            [
                                'path' => 'multi-level2',
                                'component' => 'demo/multi-level/children/level2',
                                'name' => 'MultiLevel2',
                                'meta' => [
                                    'title' => '菜单二级',
                                    'icon' => '',
                                    'hidden' => false,
                                    'roles' => ['ADMIN'],
                                    'alwaysShow' => false,
                                    'params' => null,
                                ],
                                'children' => [
                                    [
                                        'path' => 'multi-level3-1',
                                        'component' => 'demo/multi-level/children/children/level3-1',
                                        'name' => 'MultiLevel31',
                                        'meta' => [
                                            'title' => '菜单三级-1',
                                            'icon' => '',
                                            'hidden' => false,
                                            'roles' => ['ADMIN'],
                                            'keepAlive' => true,
                                            'alwaysShow' => false,
                                            'params' => null,
                                        ],
                                    ],
                                    [
                                        'path' => 'multi-level3-2',
                                        'component' => 'demo/multi-level/children/children/level3-2',
                                        'name' => 'MultiLevel32',
                                        'meta' => [
                                            'title' => '菜单三级-2',
                                            'icon' => '',
                                            'hidden' => false,
                                            'roles' => ['ADMIN'],
                                            'keepAlive' => true,
                                            'alwaysShow' => false,
                                            'params' => null,
                                        ],
                                    ],
                                ],
                            ],
                        ],
                    ],
                ],
            ],
            [
                'path' => '/component',
                'component' => 'Layout',
                'name' => '/component',
                'meta' => [
                    'title' => '组件封装',
                    'icon' => 'menu',
                    'hidden' => false,
                    'roles' => ['ADMIN'],
                    'alwaysShow' => false,
                    'params' => null,
                ],
                'children' => [
                    [
                        'path' => 'curd',
                        'component' => 'demo/curd/index',
                        'name' => 'Curd',
                        'meta' => [
                            'title' => '增删改查',
                            'icon' => '',
                            'hidden' => false,
                            'roles' => ['ADMIN'],
                            'keepAlive' => true,
                            'alwaysShow' => false,
                            'params' => null,
                        ],
                    ],
                    [
                        'path' => 'table-select',
                        'component' => 'demo/table-select/index',
                        'name' => 'TableSelect',
                        'meta' => [
                            'title' => '列表选择器',
                            'icon' => '',
                            'hidden' => false,
                            'roles' => ['ADMIN'],
                            'keepAlive' => true,
                            'alwaysShow' => false,
                            'params' => null,
                        ],
                    ],
                    [
                        'path' => 'wang-editor',
                        'component' => 'demo/wang-editor',
                        'name' => 'WangEditor',
                        'meta' => [
                            'title' => '富文本编辑器',
                            'icon' => '',
                            'hidden' => false,
                            'roles' => ['ADMIN'],
                            'keepAlive' => true,
                            'alwaysShow' => false,
                            'params' => null,
                        ],
                    ],
                    [
                        'path' => 'upload',
                        'component' => 'demo/upload',
                        'name' => 'Upload',
                        'meta' => [
                            'title' => '图片上传',
                            'icon' => '',
                            'hidden' => false,
                            'roles' => ['ADMIN'],
                            'keepAlive' => true,
                            'alwaysShow' => false,
                            'params' => null,
                        ],
                    ],
                    [
                        'path' => 'icon-selector',
                        'component' => 'demo/icon-selector',
                        'name' => 'IconSelector',
                        'meta' => [
                            'title' => '图标选择器',
                            'icon' => '',
                            'hidden' => false,
                            'roles' => ['ADMIN'],
                            'keepAlive' => true,
                            'alwaysShow' => false,
                            'params' => null,
                        ],
                    ],
                    [
                        'path' => 'dict-demo',
                        'component' => 'demo/dict',
                        'name' => 'DictDemo',
                        'meta' => [
                            'title' => '字典组件',
                            'icon' => '',
                            'hidden' => false,
                            'roles' => ['ADMIN'],
                            'keepAlive' => true,
                            'alwaysShow' => false,
                            'params' => null,
                        ],
                    ],
                ],
            ],
            [
                'path' => '/route-param',
                'component' => 'Layout',
                'name' => '/routeParam',
                'meta' => [
                    'title' => '路由参数',
                    'icon' => 'el-icon-ElementPlus',
                    'hidden' => false,
                    'roles' => ['ADMIN'],
                    'alwaysShow' => true,
                    'params' => null,
                ],
                'children' => [
                    [
                        'path' => 'route-param-type1',
                        'component' => 'demo/route-param',
                        'name' => 'RouteParamType1',
                        'meta' => [
                            'title' => '参数(type=1)',
                            'icon' => 'el-icon-Star',
                            'hidden' => false,
                            'roles' => ['ADMIN'],
                            'keepAlive' => true,
                            'alwaysShow' => false,
                            'params' => [
                                'type' => '1',
                            ],
                        ],
                    ],
                    [
                        'path' => 'route-param-type2',
                        'component' => 'demo/route-param',
                        'name' => 'RouteParamType2',
                        'meta' => [
                            'title' => '参数(type=2)',
                            'icon' => 'el-icon-StarFilled',
                            'hidden' => false,
                            'roles' => ['ADMIN'],
                            'keepAlive' => true,
                            'alwaysShow' => false,
                            'params' => [
                                'type' => '2',
                            ],
                        ],
                    ],
                ],
            ],
            [
                'path' => '/function',
                'component' => 'Layout',
                'name' => '/function',
                'meta' => [
                    'title' => '功能演示',
                    'icon' => 'menu',
                    'hidden' => false,
                    'roles' => ['ADMIN'],
                    'alwaysShow' => false,
                    'params' => null,
                ],
                'children' => [
                    [
                        'path' => 'icon-demo',
                        'component' => 'demo/icons',
                        'name' => 'IconDemo',
                        'meta' => [
                            'title' => 'Icons',
                            'icon' => 'el-icon-Notification',
                            'hidden' => false,
                            'roles' => ['ADMIN'],
                            'keepAlive' => true,
                            'alwaysShow' => false,
                            'params' => null,
                        ],
                    ],
                    [
                        'path' => '/function/websocket',
                        'component' => 'demo/websocket',
                        'name' => '/function/websocket',
                        'meta' => [
                            'title' => 'Websocket',
                            'icon' => '',
                            'hidden' => false,
                            'roles' => ['ADMIN'],
                            'keepAlive' => true,
                            'alwaysShow' => false,
                            'params' => null,
                        ],
                    ],
                    [
                        'path' => 'other/:id',
                        'component' => 'demo/other',
                        'name' => 'Other/:id',
                        'meta' => [
                            'title' => '敬请期待...',
                            'icon' => '',
                            'hidden' => false,
                            'roles' => ['ADMIN'],
                            'alwaysShow' => false,
                            'params' => null,
                        ],
                    ],
                ],
            ],
        ];

        $data = $this->service->getRoutes();
        return $this->succ($data);
    }

    public function tree()
    {
        $result = $this->service->tree();
        return  $this->succ($result);
    }
    public function options()
    {
        $result = $this->service->optionTree();
        return  $this->succ($result);
    }

    public function store(){
        $result = $this->service->store($this->request->all());
        return $this->succ($result);
    }

    public function update($id){
        $result = $this->service->store($this->request->all(),$id);
        return $this->succ($result);
    }

    public function detail($id){
        $result = $this->service->show($id);
        return $this->succ(new MenuResource($result));
    }

}

